package com.creditnet.bmc.platform.config;

import com.creditnet.bmc.platform.filter.XssFilter;
import com.google.common.collect.Maps;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

/**
 * Created by bjmaozhengwei on 2018/3/31.
 */
@Configuration
public class XssConfig {
    /**
     * xss过滤拦截器
     */
    FilterRegistrationBean xssFilterRegistrationBean(){
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setFilter(new XssFilter());
        filterRegistrationBean.setOrder(1);
        filterRegistrationBean.setEnabled(false);
        filterRegistrationBean.addUrlPatterns("/*");
        Map<String,String> initParameters = Maps.newHashMap();
        initParameters.put("excludes","/favicon.ico,/img/*,/js/*,/css/*");
        initParameters.put("isIncludeRichText", "true");
        filterRegistrationBean.setInitParameters(initParameters);
        return filterRegistrationBean;
    }
}
